<template>
	<view>
		<van-swipe-cell  right-width="65" v-for="(item,index) in cv" :key="index" class="tutu">
			<!-- <view class="fuxuan"> -->
				<van-checkbox class="fuxuan" :value="item.flag" @change="onChang(index)"></van-checkbox>
			<!-- </view> -->
			
		 <van-card
		   :price="item.price"
		   :title="item.name"
		   :thumb="item.img"
		 >
		  <view slot="num">
			  <van-stepper  :value="item.bumn" @plus="onChan(index)" @minus="onChann(index)" />
		  </view>
		 </van-card>
		 <view slot="right" class="scdff">删除</view>
		</van-swipe-cell>
		<van-submit-bar
		  :price="xc*100"
		  button-text="提交订单"
		  @submit="onClickButton"
		 
		>
		 
			<van-checkbox :value="checked" @change="onChange"></van-checkbox>
		  
		  
		</van-submit-bar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cv:[],
				checked:false,
				num:0
			}
		},
		methods: {
			onChange(){
				this.checked=!this.checked
				this.cv.forEach(item=>{
				   item.flag=this.checked
				})
				
				
			},
			onChang(k){
				this.cv[k].flag=!this.cv[k].flag
			},
			onChan(e){
				// console.log(e);
				this.cv[e].bumn+=1
				wx.setStorageSync('wee',this.cv)
			},
			onChann(e){
				this.cv[e].bumn-=1
				wx.setStorageSync('wee',this.cv)
			},
			xc(){
				var numm=0
				var bn=this.cv.filter(item=>{
					return item.flag==true
				})
				bn.forEach(item=>{
					numm+=item.bnum*item.price
				})
				// console.log(num);
				return nummm
				// console.log(num);
			}
		},
		onLoad() {
			this.cv=wx.getStorageSync('wee')||[]
			// console.log(cv);
			
		},
		watch:{
			cv:{
				handler(val){
					wx.setStorageSync('wee',val)
				},
				deep:true
			}
		},
		watch:{
			cv:{
				handler(val){
					
					var obj=val.filter(item=>{
						return item.flag==true
					})
					if(obj.length==val.length){
						this.checked=true
					}else{
						this.checked=false
					}
				},
				deep:true,
				immediate:true
			}
		}
	}
</script>

<style>
.scdff{
		width: 210%;
		background-color: #a52a2a;
	    height: 100%;
		color: #ffffff;
		text-align: center;
		line-height: 200rpx;
}
.van-card{
	margin-left: 100rpx;
}
.fuxuan{
	position: absolute;
	top: 100rpx;
	left: 30rpx;
}
</style>
